<?php
declare(strict_types=1);

namespace App\Service;

use http\Env\Request;
use Hyperf\RpcServer\Annotation\RpcService;
use Mrx\Core\Dto\User\MemberDto;
use Mrx\Core\JsonRpc\User\UserServiceInterface;
use App\Mapper\UserMapper;
use Mrx\Core\Service\AbstractService;
use Mrx\Core\Response\ResponseResult;
use Mrx\Core\Exception\JsonRpcException;
use App\Dto\TestDto;
/**
 * @Desc:用户管理服务
 * @Class: UserService
 * @Package: App\Service
 * @Author: mrx
 * @CreateTime: 2023-07-12  15:17
 * @Version: 1.0
 */
#[RpcService(name: "UserService", server: "jsonrpc-http", protocol: "jsonrpc-http", publishTo: "nacos")]
class UserService extends AbstractService implements UserServiceInterface
{
    /**
     * @var UserMapper
     */
    public $mapper;

    public function __construct(UserMapper $mapper)
    {
        $this->mapper = $mapper;
    }

    /**
     * @Desc:通过用户id获取用户信息
     * @Funtion: getUserInfoByUserId
     * @Author: mrx
     * @CreateTime: 2023-07-12
     * @param int $userId
     * @return mixed|void
     */
    public function getUserInfoByUserId(int $userId)
    {
        if ($userId <= 0) {
            throw new JsonRpcException(4000);
        }
        return $this->mapper->getUserInfoById($userId);
    }

    /**
     * @Desc:通过用户名获取用户信息
     * @Funtion: getUserInfoByUserName
     * @Author: mrx
     * @CreateTime: 2023-07-13
     * @param string $userName
     * @return mixed|void
     */
    public function getUserInfoByUserName(string $userName)
    {

    }

    /**
     * @Desc:用户注册
     * @Funtion: register
     * @Author: mrx
     * @CreateTime: 2023-07-13
     * @param MemberDto $dto
     * @return mixed|void
     */
    public function register(MemberDto $dto)
    {
       $res = $this->mapper->save($dto->getData());
       if(!$res){
           return ResponseResult::error();
       }
       return ResponseResult::success();
    }
}